import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class ThreadDemo_Callable {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        MyCallable2 myCallable = new MyCallable2();

        FutureTask<Integer> futureTask = new FutureTask<Integer>(myCallable);

        Thread thread = new Thread(futureTask);

        thread.start();

        int result = futureTask.get();

        System.out.println(result);
    }
    
    static class MyCallable2 implements Callable<Integer> {

        @Override
        public Integer call() throws Exception {
            int ans = 0;
            for (int i = 1; i <= 1000; i++) {
                ans +=i;
            }
            return ans;
        }
    }
}
